#pragma once
#include "redBlackTree.h"

namespace hd
{
	template <class k, class v>
	class map
	{
		struct MapKeyOfT
		{
			const k& operator()(const pair<k, v>& kv)
			{
				return kv.first;
			}
		};

		RBTree<k, pair<const k, v>, MapKeyOfT> _t;

	public:
		typedef typename RBTree<k, pair<const k, v>, MapKeyOfT>::iterator iterator;
		typedef typename RBTree<k, pair<const k, v>, MapKeyOfT>::const_iterator const_iterator;

		map()
		{

		}

		map(const initializer_list<pair<const k, v>>& il)
			:_t(il)
		{

		}

		pair<iterator, bool> insert(const pair<k, v>& kv)
		{
			return _t.Insert(kv);
		}

		iterator begin()
		{
			return _t.Begin();
		}
		const_iterator begin()const
		{
			return _t.Begin();
		}
		iterator end()
		{
			return _t.End();
		}
		const_iterator end()const
		{
			return _t.End();
		}
		iterator find(const k& key)
		{
			return _t.Find(key);
		}
		const_iterator find(const k& key)const
		{
			return _t.Find(key);
		}
		v& operator[](const k& key)
		{
			pair<iterator, bool> ret = insert({ key, v() });
			return ret.first->second;
		}
	};
}